package com.example.adminui.service.impl;

/**
 * 销售服务实现类
 * 提供销售相关的业务逻辑实现
 */

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.example.adminui.entity.Sales;
import com.example.adminui.entity.SalesPerformance;
import com.example.adminui.mapper.SalesMapper;
import com.example.adminui.mapper.SalesPerformanceMapper;
import com.example.adminui.service.SalesService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.List;

@Service
public class SalesServiceImpl implements SalesService {

    /**
     * 销售数据访问接口
     */
    @Autowired
    private SalesMapper salesMapper;

    @Autowired
    private SalesPerformanceMapper salesPerformanceMapper;

    /**
     * 获取所有销售信息
     * @return 销售列表
     */

    @Override
    public List<Sales> getAllSales() {
        return salesMapper.selectList(new QueryWrapper<>());
    }

        /**
     * 根据ID获取销售信息
     * @param id 销售ID
     * @return 销售信息
     */
    @Override
    public Sales getSalesById(Long id) {
        return salesMapper.selectById(id);
    }

        /**
     * 创建新销售记录
     * @param sales 销售信息
     */
    @Override
    public void createSales(Sales sales) {
        salesMapper.insert(sales);
    }

        /**
     * 更新销售信息
     * @param sales 销售信息
     */
    @Override
    public void updateSales(Sales sales) {
        salesMapper.updateById(sales);
    }

        /**
     * 删除销售记录
     * @param id 销售ID
     */
    @Override
    public void deleteSales(Long id) {
        salesMapper.deleteById(id);
    }

        /**
     * 获取某月的销售业绩
     * @param month 月份
     * @return 销售业绩列表
     */
    @Override
    public List<SalesPerformance> getSalesPerformanceByMonth(String month) {
        QueryWrapper<SalesPerformance> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("month", month);
        return salesPerformanceMapper.selectList(queryWrapper);
    }

        /**
     * 根据ID获取销售业绩
     * @param id 销售业绩ID
     * @return 销售业绩信息
     */
    @Override
    public SalesPerformance getSalesPerformanceById(Long id) {
        return salesPerformanceMapper.selectById(id);
    }

        /**
     * 创建销售业绩记录
     * @param salesPerformance 销售业绩信息
     */
    @Override
    public void createSalesPerformance(SalesPerformance salesPerformance) {
        salesPerformanceMapper.insert(salesPerformance);
    }

        /**
     * 更新销售业绩记录
     * @param salesPerformance 销售业绩信息
     */
    @Override
    public void updateSalesPerformance(SalesPerformance salesPerformance) {
        salesPerformanceMapper.updateById(salesPerformance);
    }

        /**
     * 删除销售业绩记录
     * @param id 销售业绩ID
     */
    @Override
    public void deleteSalesPerformance(Long id) {
        salesPerformanceMapper.deleteById(id);
    }
}